home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 5 / Eagles_Nest_Mac_Collection_Disc_5.TOAST / Other Non-Macintosh Text / CDVvalidate < prev    next >
Text File  |  1993-09-03  |  3KB  |  123 lines

  1. The first part of this doument is a quick summary of card number input
  2. validation criteria. The second part of this document is a general description
  3. of the MOD 10 cdv  algorithm.  The third part is a VAX BASIC implementation of a
  4. MOD 10 cdv  validation routine. The algorith and the program came from different
  5. sources, and so do not necessarily reflect one another.  The BASIC program does
  6. indeed work, and will ID bad credit card input.
  7.  
  8.  
  9. Card Number Validation
  10. **********************
  11.  
  12. VISA        starts with "4"    len = 13 or 16
  13. MasterCard  starts with "5"    len = 13 or 16
  14. Discover    starts with "6011" len = 16
  15. Amex        starts with "37"   len = 15
  16.  
  17. ? Diners, Carte Blanche starts with "38", len = 15 (not sure on this one)
  18.  
  19. all card numbers are mod 10 CDV'd
  20.  
  21.  
  22.  
  23. MOD 10 CDV algorithm
  24. ********************
  25.  
  26. A) Starting from thr RIGHTMOST digit and working to the left, multiply one 
  27. digit by 2, the next by 1, the next by and so forth.
  28.  
  29. B) Sum the digits of any two digit numbers produced.
  30.  
  31. C) Add all of the resultant figures.
  32.  
  33. D) Subtract that number from the next highest multiple of 10 and use that 
  34. as a check digit.
  35.  
  36. examples:
  37.  
  38. #       12345            11111            66666           126749
  39.  
  40. A)      2,2,6,4,10       2,1,2,1,2        12,6,12,6,12    1,4,6,14,4,18
  41. B)      2,2,6,4,1        2,1,2,1,2        3,6,3,6,3       1,4,6,5,4,9
  42. C)      15               8                21              29
  43. D)      5                2                9               1
  44.  
  45.         123455           111112           666669          1267491
  46.  
  47.  
  48.  
  49.  
  50. MOD 10 cdv validation program
  51. *****************************
  52.  
  53. function byte mod_10_cdv(string s$_in)
  54. !     description   :   Performs a MOD 10 CDV validation of a 
  55. !               numeric string.  Accomodates numbers of
  56. !               up to 20 digits in length. returns -1 if cdv is correct
  57. !                                                   0 if not
  58. !
  59.  
  60.     option type = explicit
  61.  
  62.     declare string constant c$_s_zero_fill_1  = "<0>"
  63.  
  64.     record cdv_string
  65.        variant
  66.           case
  67.         string s$_digits = 20%
  68.           case
  69.         string s$_digit(1% to 20%) = 1%
  70.        end variant
  71.     end record
  72.  
  73.     declare cdv_string cdv
  74.  
  75.     declare byte    b$_idx                  &
  76.     ,       b$_digit
  77.  
  78.     declare double  d$_total                &
  79.     ,       d$_1                            &
  80.     ,       d$_2
  81.  
  82.     declare string s$_number
  83.  
  84.  
  85.     on error goto error_handler
  86.  
  87.  
  88.     mod_10_cdv = 0%
  89.  
  90.     s$_number = edit$(s$_in, -1%)
  91.  
  92.     exit function if len(s$_number) > 20%
  93.  
  94.     rset cdv::s$_digits = "00000000000000000000" + s$_number
  95.  
  96.     for b$_idx = 1% to 19% step 2%
  97.        b$_digit = 2 * integer(cdv::s$_digit(b$_idx), byte)
  98.        b$_digit = b$_digit - 9% if b$_digit > 9%
  99.        cdv::s$_digit(b$_idx) = format$(b$_digit, c$_s_zero_fill_1)
  100.     next b$_idx
  101.  
  102.     d$_total = 0.0
  103.     for b$_idx = 1% to 19%
  104.        d$_total = d$_total + real(cdv::s$_digit(b$_idx), double)
  105.     next b$_idx
  106.  
  107.     d$_1 = (d$_total - (int (d$_total / 10)) * 10) + real(cdv::s$_digit(20%), double)
  108.  
  109.     d$_2 = int(d$_1 / 10)
  110.                                 
  111.     if (d$_1 - (d$_2 * 10)) = 0 then
  112.        mod_10_cdv = -1%
  113.     end if
  114.  
  115.     exit function
  116.  
  117.  
  118. error_handler:
  119.     resume exit_function
  120.  
  121. exit_function:
  122.     end function
  123.